package com.tencent.sr.iris.basic.saas.restapi.message;

import com.tencent.sr.iris.basic.saas.interfaces.request.message.UserMessageConfigStatusUpdateRequest;
import com.tencent.sr.iris.basic.saas.service.message.UserMessageConfigService;
import com.tencent.sr.iris.basic.service.interfaces.dto.UserMessageConfigDTO;
import com.tencent.sr.iris.basic.service.interfaces.request.message.UserMessageBaseRequest;
import com.tencent.sr.iris.basic.service.interfaces.request.message.UserMessageConfigRequest;
import com.tencent.sr.rmall.common.primitive.HttpResult;
import com.tencent.sr.rmall.common.request.PaginationRequest;
import com.tencent.sr.rmall.common.response.PaginationResponse;
import com.tencent.sr.rmall.springbootstarter.authtoken.localbean.AppUser;
import com.tencent.sr.rmall.springbootstarter.utils.BeanCopierUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 消息配置接口
 *
 * @author xiaodongguo
 * @Date: 2021/1/16
 */
@Api(tags = "消息配置接口", value = "消息配置接口")
@RestController
@RequestMapping(value = {"/iris/basic/saas/v1/messageconfig/"})
public class UserMessageConfigController {

    @Resource
    private AppUser appUser;

    @Resource
    private UserMessageConfigService userMessageConfigService;

    @PostMapping("/createMessageConfig")
    @ApiOperation(value = "新增配置")
    public HttpResult<Boolean> createMessageConfig(@RequestBody @Validated UserMessageConfigRequest request) {
        request.setSaasId(String.valueOf(appUser.getManageSession().getRootSaaSId()));
        return HttpResult.succ(userMessageConfigService.createConfig(request));
    }

    @PostMapping("/queryUserMessageConfigList")
    public HttpResult<PaginationResponse<UserMessageConfigDTO>> queryUserMessageConfigList(
            @RequestBody @Validated PaginationRequest<Void> request) {
        PaginationRequest<UserMessageBaseRequest> realRequest = new PaginationRequest<>();
        BeanCopierUtil.copy(request, realRequest);

        UserMessageBaseRequest userMessageBaseRequest = new UserMessageBaseRequest();
        userMessageBaseRequest.setSaasId(String.valueOf(appUser.getManageSession().getRootSaaSId()));
        realRequest.setQueryCriteria(userMessageBaseRequest);
        return HttpResult.succ(userMessageConfigService.queryUserMessageConfigList(realRequest));
    }

    @PostMapping("/updateStatus")
    public HttpResult<Boolean> updateStatus(@RequestBody @Validated UserMessageConfigStatusUpdateRequest request) {
        return HttpResult.succ(userMessageConfigService.updateStatus(request));
    }
}
